/*
* 用于用户个人信息修改js
* */
layui.use([ 'layer', 'upload', 'element','form'], function() {
    var layer = layui.layer //弹层
        , upload = layui.upload //上传
        , element = layui.element //元素操作
        ,form = layui.form;

    var userId = $("#userId").val();
    /*头像上传*/
    var uploadInst = upload.render({
        elem: '#test1'
        ,url: '/user/img/'+userId
        ,before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#demo1').attr('src', result); //图片链接（base64）
            });
        }
        ,done: function(res,index,upload){
            //如果上传失败
            if(res.code > 0){
                return layer.msg('修改失败');
            }else{
                return layer.msg('修改成功');
            }
        }
        ,error: function(){
            //演示失败状态，并实现重传
            var demoText = $('#demoText');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function(){
                uploadInst.upload();
            });
        }
    });

    /*基本资料修改*/
    form.on('submit(LAY_btn_save)', function(data){
        $.ajax({
           url:'/user/renewal' ,
            type:'post',
            data:data.field,
            success:function(obj){
               layer.alert(obj,{
                   title:'系统提示'
               });
            }
        });
        return false;
    });
});
